package com.fanxuankai.boot.mqbroker.producer.autoconfigure;

import cn.hutool.core.text.StrPool;
import com.fanxuankai.boot.mqbroker.producer.AbstractMqProducer;
import com.fanxuankai.boot.mqbroker.producer.MqProducer;
import com.fanxuankai.boot.mqbroker.producer.MsgSendService;
import com.fanxuankai.boot.mqbroker.producer.RabbitProducer;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

/**
 * @author fanxuankai
 */
@ConditionalOnClass({AmqpAdmin.class})
@ConditionalOnProperty(name = MqBrokerProducerProperties.ENABLED, matchIfMissing = true)
public class MqBrokerProducerRabbitAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean(MqProducer.class)
    public AbstractMqProducer mqProducer(MsgSendService msgSendService, AmqpAdmin amqpAdmin,
                                         ConnectionFactory connectionFactory, RabbitProperties rabbitProperties,
                                         MqBrokerProducerProperties properties) {
        return new RabbitProducer(msgSendService, amqpAdmin, connectionFactory, rabbitProperties,
                properties, StrPool.COMMA);
    }
}
